package com.example.studentmanagement.util;

import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import com.example.studentmanagement.entity.Student;

import java.util.ArrayList;
import java.util.List;

public class DBUtil extends SQLiteOpenHelper {

    public static SQLiteDatabase db=null;


    private static final String DATABASE_NAME="db_student.db";//数据库名字

    private static final int DATABASE_VERSION=6;

    public DBUtil(Context context){
        super(context,DATABASE_NAME,null,DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db){



        db.execSQL("PRAGMA foreign_keys = false");
        //-----------建立学生（用户）表
        db.execSQL("DROP TABLE IF EXISTS d_student");
        db.execSQL("CREATE TABLE d_student  (\n" +
                "  s_id varchar(20) NOT NULL,\n" +
                "  s_pwd  ,\n" +
                "  s_name varchar(20) ,\n" +
                "  s_pro varchar(20) ,\n" +
                "  s_sex varchar(20) ,\n" +
                "  PRIMARY KEY (s_id) \n" +
                ")");
        db.execSQL("INSERT INTO d_student VALUES ('20210001181', '123', '邱靖钦', '21级计算机四班', '男')");
        db.execSQL("INSERT INTO d_student VALUES ('root', 'root', 'Administrators', 'Administrators', '男')");
        //-----------建立管理员表
        db.execSQL("DROP TABLE IF EXISTS d_admin");
        db.execSQL("CREATE TABLE d_admin  (\n" +
                "  d_id varchar(20) NOT NULL,\n" +
                "  d_pwd  ,\n" +
                "  PRIMARY KEY (d_id) \n" +
                ")");
        db.execSQL("INSERT INTO d_admin VALUES ('root', 'root')");




        db.execSQL("DROP TABLE IF EXISTS c_cur");
        db.execSQL( "CREATE TABLE c_cur (" +
                "cName TEXT NOT NULL ," +
                "cId TEXT PRIMARY KEY ," +
                "cTeacher TEXT NOT NULL ," +
                "cClass TEXT ," +
                "cTime INT )" );
        db.execSQL("INSERT INTO c_cur VALUES ('美食鉴赏', '1','老八','食品一班','24')");

        db.execSQL("DROP TABLE IF EXISTS choose");
        db.execSQL( "CREATE TABLE choose (" +
                "chooseId TEXT NOT NULL PRIMARY KEY ," +
                "studentId TEXT NOT NULL ,"+
                "curriculumId Text NOT NULL )");
        db.execSQL("INSERT INTO choose VALUES ('1', '20210001181','1')");

        db.execSQL("PRAGMA foreign_keys = true");

    }

    @Override
    public void onUpgrade(SQLiteDatabase db,int i,int i1) {

        onCreate(db);
    }




}
